package com.example.erp;

import java.time.Duration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import io.modelcontextprotocol.client.McpClient;
import io.modelcontextprotocol.client.McpSyncClient;
import io.modelcontextprotocol.client.transport.ServerParameters;
import io.modelcontextprotocol.client.transport.StdioClientTransport;
import io.modelcontextprotocol.spec.McpSchema;

/**
 * 通过bean方式注入 server-filesystem 配置信息.
 */
@Configuration
public class ClientConfig {

	@Bean(destroyMethod = "close")
	McpSyncClient mcpClient() {
		var stdioParams = ServerParameters.builder("D:\\dev\\Nodejs\\npx.cmd")
				.args("-y", "@modelcontextprotocol/server-filesystem", "D:\\share")
				.build();
		
		var transport = new StdioClientTransport(stdioParams);
		
		var mcpClient = McpClient.sync(transport)
				.requestTimeout(Duration.ofSeconds(10))
				.clientInfo(new McpSchema.Implementation("jiang-mcp-client-java", "1.0.0"))
				.build();

		var init = mcpClient.initialize();

		System.err.println("MCP Initialized: " + init);

		return mcpClient;

	}
}
